<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户管理系统</title>
    <!-- 引入 Bootstrap CSS -->
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.7/css/bootstrap.min.css" rel="stylesheet">
    <!-- 引入 Font Awesome -->
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.5.0/css/all.min.css" rel="stylesheet">
    <!-- 引入自定义样式 -->
    <link rel="stylesheet" href="css/style.css">
    <!-- toastify.js CSS -->
    <link href="https://cdn.bootcdn.net/ajax/libs/toastify-js/1.12.0/toastify.css" rel="stylesheet">
    <!-- toastify.js JS -->
    <script src="https://cdn.bootcdn.net/ajax/libs/toastify-js/1.12.0/toastify.min.js"></script>
    <!-- Grid.js CSS -->
    <link href="https://cdn.bootcdn.net/ajax/libs/gridjs/6.2.0/theme/mermaid.min.css" rel="stylesheet" />
    <!-- Grid.js JS -->
    <script src="https://cdn.bootcdn.net/ajax/libs/gridjs/6.2.0/gridjs.umd.js"></script>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <!-- 侧边栏 -->
        <nav class="col-md-3 col-lg-2 d-md-block bg-light sidebar">
            <div class="position-sticky">
                <div class="sidebar-brand d-flex align-items-center px-3 py-3 border-bottom">
                    <i class="fas fa-user-cog fa-2x me-2 text-primary"></i>
                    <span class="fs-5 fw-bold">用户管理系统</span>
                </div>
                <ul class="nav flex-column pt-3">
                    <li class="nav-item pt-2">
                        <a class="nav-link active" href="#" id="userManagementLink">
                            <i class="fas fa-users fa-fw me-2"></i>
                            用户管理
                        </a>
                    </li>
                    <li class="nav-item pt-2">
                        <a class="nav-link" href="#" id="departmentManagementLink">
                            <i class="fas fa-building fa-fw me-2"></i>
                            部门管理
                        </a>
                    </li>
                    <li class="nav-item pt-2">
                        <a class="nav-link" href="#" id="roleManagementLink">
                            <i class="fas fa-user-tag fa-fw me-2"></i>
                            角色管理
                        </a>
                    </li>
                    <li class="nav-item pt-2">
                        <a class="nav-link" href="profile.html" id="profileLink">
                            <i class="fas fa-user-circle fa-fw me-2"></i>
                            个人信息
                        </a>
                    </li>
                    <li class="nav-item pt-2">
                        <a class="nav-link" href="#" id="logoutLink" onclick="logout()">
                            <i class="fas fa-sign-out-alt fa-fw me-2"></i>
                            退出登录
                        </a>
                    </li>
                </ul>
            </div>
        </nav>

        <!-- 主内容区域 -->
        <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
            <!-- ========== 页头：标题 + 操作区 ========== -->
            <div class="row mb-4">
            <div class="col-12 d-flex justify-content-between align-items-center">
                <div>
                    <h2 class="mb-0">
                        <i class="fas fa-users text-primary me-2"></i>
                        用户管理
                    </h2>
                </div>
                <div>
                    <button data-bs-toggle="modal" data-bs-target="#addModal" class="btn btn-success">
                        <i class="fas fa-plus-circle me-1"></i> 新增用户
                    </button>
                    <button class="btn btn-outline-secondary ms-2" id="btnRefresh" onclick="initGrid()">
                        <i class="fas fa-sync-alt me-1"></i> 刷新
                    </button>
                </div>
            </div>
            </div>

        <!-- ========== 用户列表卡片 ========== -->
        <div class="row">
            <div class="col-12">
                <div class="card-header bg-white d-flex justify-content-between align-items-center border-bottom">
                    <h5 class="mb-0">
                        <i class="fas fa-list-ul m-2"></i>
                        用户数据列表
                    </h5>
                </div>
                <div class="card-body p-0">
                    <div class="table-responsive">
                        <!-- Grid.js 将挂载到这个 div -->
                        <div id="gridjs-container"></div>
                    </div>
                </div>
            </div>
        </div>

    <div class="modal fade modal-lg" id="addModal" tabindex="-1" aria-labelledby="addModalLabel" aria-hidden="true">
            <form id="add-form" class="needs-validation" novalidate>
                <input type="hidden" class="form-control" name="avatar" />
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="addModalLabel">新增用户</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body">
                            <div class="px-5">
                            <div id="alertAddMessage"></div>
                            <div class="row mb-3">
                                <label for="username" class="col-sm-2 col-form-label d-flex justify-content-end">账号</label>
                                <div class="col-sm-10">
                                <input type="text" class="form-control" id="username" name="username" required>
                                </div>
                            </div>
                            <div class="row mb-3">
                                <label for="name" class="col-sm-2 col-form-label d-flex justify-content-end">用户名</label>
                                <div class="col-sm-10">
                                <input type="text" class="form-control" id="name" name="name" required>
                                </div>
                            </div>
                            <div class="row mb-3">
                                <label for="password" class="col-sm-2 col-form-label d-flex justify-content-end">密码</label>
                                <div class="col-sm-10">
                                <input type="password" class="form-control" id="password" name="password" required>
                                </div>
                            </div>
                            <div class="row mb-3">
                                <label for="phone" class="col-sm-2 col-form-label d-flex justify-content-end">手机号码</label>
                                <div class="col-sm-10">
                                <input type="text" class="form-control" id="phone" name="phone">
                                </div>
                            </div>
                            <div class="row mb-3">
                                <label for="email" class="col-sm-2 col-form-label d-flex justify-content-end">邮箱</label>
                                <div class="col-sm-10">
                                <input type="email" class="form-control" id="email" name="email">
                                </div>
                            </div>
                            <div class="row mb-3">
                                <legend class="col-sm-2 col-form-label d-flex justify-content-end">部门</legend>
                                <div class="col-sm-10">
                                <select name="deptId" class="form-select" aria-label="select dept" required>
                                </select>
                                </div>
                            </div>
                            <div class="row mb-3">
                                <legend class="col-sm-2 col-form-label d-flex justify-content-end">角色</legend>
                                <div class="col-sm-10">
                                <select name="roleId" class="form-select" aria-label="select role" required>
                                </select>
                                </div>
                            </div>
                            <div class="row mb-3">
                                <label for="fileInput" class="col-sm-2 col-form-label d-flex justify-content-end">头像</label>
                                <div class="col-sm-10">
                                <input type="file" class="form-control" id="fileInput">
                                </div>
                            </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" name="close" data-bs-dismiss="modal">关闭</button>
                            <button type="submit" class="btn btn-primary">提交</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        
         <div class="modal fade modal-lg" id="editModal" tabindex="-1" aria-labelledby="editModalLabel" aria-hidden="true">
            <form id="edit-form" class="needs-validation" novalidate>
                <input type="hidden" class="form-control" name="id" />
                <input type="hidden" class="form-control" name="avatar" />
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="editModalLabel">编辑用户</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body">
                            <div class="px-5">
                                <div id="alertEditMessage"></div>
                                <div class="row mb-3">
                                    <label for="e_username" class="col-sm-2 col-form-label d-flex justify-content-end">账号</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control" id="e_username" name="username" required>
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <label for="e_name" class="col-sm-2 col-form-label d-flex justify-content-end">用户名</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control" id="e_name" name="name" required>
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <label for="e_phone" class="col-sm-2 col-form-label d-flex justify-content-end">手机号码</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control" id="e_phone" name="phone">
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <label for="e_email" class="col-sm-2 col-form-label d-flex justify-content-end">邮箱</label>
                                    <div class="col-sm-10">
                                        <input type="email" class="form-control" id="e_email" name="email">
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <legend class="col-sm-2 col-form-label d-flex justify-content-end">部门</legend>
                                    <div class="col-sm-10">
                                        <select name="deptId" class="form-select" aria-label="select dept" required>
                                        </select>
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <legend class="col-sm-2 col-form-label d-flex justify-content-end">角色</legend>
                                    <div class="col-sm-10">
                                        <select name="roleId" class="form-select" aria-label="select role" required>
                                        </select>
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <label for="e_fileInput" class="col-sm-2 col-form-label d-flex justify-content-end">头像</label>
                                    <div class="col-sm-10">
                                        <input type="file" class="form-control" id="e_fileInput">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" name="close" data-bs-dismiss="modal">关闭</button>
                            <button type="submit" class="btn btn-primary">提交</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
     </main>
    </div>
</div>


    <!-- 引入 Bootstrap JS（含 Popper）-->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.7/js/bootstrap.bundle.min.js"></script>
    <!-- 引入自定义脚本 -->
    <script src="js/user.js"></script>
</body>
</html>